const {
    log
} = console
const arr = [1, [2, [3, [4, [5, [new Function, [Symbol(6)]]]]]]]
const arr1 = [1, [2, [3]]]
// 1. JSON函数 缺点：只适用与不含有 Function 和 Symbol 类型的数组
let flatByJSON = arr => {
    return JSON.parse('[' + JSON.stringify(arr).replace(/\[|\]/g, '') + ']')
}

// 2. Array.flat()
// arr.flat(Infinity)

// 3. reduce (递归)
let flatByReduce = arr => {
    return Array.isArray(arr) ?
        arr.reduce((pre, cur) => [...pre, ...flatByReduce(cur)], []) : [arr]
    return arr.reduce((pre, cur) => {
        return pre.concat(Array.isArray(cur) ? flatByReduce(cur) : cur)
    }, [])
}

// 4. 手写函数递归
const res = []
let flatten = arr => {
    for (let i = 0; i < arr.length; i++) {
        if (Array.isArray(arr[i])) {
            flatten(arr[i])
        } else {
            res.push(arr[i])
        }
    }
}